<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">


      <el-form-item label="收款人" prop="payName">
        <el-input
          v-model="queryParams.payName"
          placeholder="请输入收款人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收款人账号" prop="payAccount">
        <el-input
          v-model="queryParams.payAccount"
          placeholder="请输入收款人账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="证件号码" prop="payCardid">
        <el-input
          v-model="queryParams.payCardid"
          placeholder="请输入证件号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="payMobile">
        <el-input
          v-model="queryParams.payMobile"
          placeholder="请输入付款人手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="商户号" prop="merId">
        <el-input
          v-model="queryParams.merId"
          placeholder="请输入商户号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="处理状态" prop="status">
        <el-select v-model="queryParams.transStatus" placeholder="请选择状态">
          <el-option
            v-for="dict in bankStatyusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="上传日期" prop="uploadDate">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="处理日期" prop="transDate">
        <el-date-picker
          v-model="dateRange2"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['fund:dircttrade:export']"
        >导出
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="detailList" @selection-change="handleSelectionChange">
      <!--el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键" align="center" prop="id"/-->
      <el-table-column label="商户编号" align="center" prop="merId"/>
      <el-table-column label="下发渠道" align="center" prop="payChannel" :formatter="payChannelFormat"/>
      <el-table-column label="批次号" align="center" prop="batchId" width="300"/>
      <el-table-column label="订单编号" align="center" prop="orderId" width="280"/>
      <el-table-column label="收款人" align="center" prop="payName"/>
      <el-table-column label="收款人账号" width="200" align="center" prop="payAccount"/>
      <el-table-column label="收款人银行" width="120" align="center" prop="payBank"/>
      <el-table-column label="付款类型" align="center" prop="payType" :formatter="payTypeFormat"/>
      <el-table-column label="证件号码" width="180" align="center" prop="payCardid"/>
      <el-table-column label="收款人手机号码" width="140" align="center" prop="payMobile"/>
      <el-table-column label="付款金额(元)" align="center" prop="payMoney"/>
      <el-table-column label="处理日期" align="center" prop="transDate" width="180">
        <template slot-scope="scope">
                      <span v-if="scope.row.transDate == null">
                      无
                      </span>
          <span v-if="scope.row.transDate != null">
                           <span>{{ parseTime(scope.row.transDate) }}</span>
                    </span>
        </template>
      </el-table-column>

      <el-table-column label="处理状态" align="center" prop="transStatus">
        <template slot-scope="scope">
           <span v-if="scope.row.transStatus == 1">
           <el-tag type="success" effect="dark" size="mini">成功</el-tag></span>
          <span v-if="scope.row.transStatus ==2">
            <el-tag type="danger" effect="dark" size="mini">失败</el-tag>
            </span>
          <span v-if="scope.row.transStatus ==0">
           <el-tag type="info" effect="dark" size="mini">未处理</el-tag>
            </span>
          <span v-if="scope.row.transStatus ==3">
             <el-tag type="warning" effect="dark" size="mini">处理中</el-tag>
           </span>

          <span v-if="scope.row.transStatus ==null">
               <el-tag type="warning" effect="dark" size="mini">处理中</el-tag>
          </span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">

        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['fund:detail:edit']"
          >查看
          </el-button>
          <span v-if="scope.row.transStatus == 3">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleCheck(scope.row)"
            v-hasPermi="['fund:detail:check']"
          >状态查询
          </el-button>
          </span>

        </template>
      </el-table-column>

    </el-table>


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改资金下发明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px">
      <el-form ref="form" size="mini" :model="form" :rules="rules" label-width="80px">

        <el-row>
          <el-col :span="10">
            <el-form-item label="商户编号:" prop="merId" labelWidth="120px">
              <span>{{ (form.merId) }}</span>
            </el-form-item>
          </el-col>

          <el-col :span="14">
            <el-form-item label="批次号:" prop="batchId" labelWidth="120px">
              <span>{{ (form.batchId) }}</span>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="订单编号:" prop="orderId" labelWidth="120px">
              <span>{{ (form.orderId) }}</span>
            </el-form-item>
          </el-col>

          <el-col :span="10">
            <el-form-item label="下发渠道:" prop="payChannel" labelWidth="120px">
              <span v-if="form.payChannel == 1">
               中国农业银行
            </span>

            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="付款人:" prop="payName" labelWidth="120px">
              <span>{{ (form.payName) }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款账号:" prop="payAccount" labelWidth="120px">
              <span>{{ (form.payAccount) }}</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="付款银行:" prop="payBank" labelWidth="120px">
              <span>{{ (form.payBank) }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="付款类型:" prop="payType" labelWidth="120px">
         <span v-if="form.payType == 1">
           对公
        </span>
              <span v-if="form.payType == 2">
           对私
        </span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="证件号码:" prop="payCardid" labelWidth="120px">
              <span>{{ (form.payCardid) }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="付款人手机号:" prop="payMobile" labelWidth="120px">
              <span>{{ (form.payMobile) }}</span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="付款金额:" prop="payMoney" labelWidth="120px">
              <span>{{ (form.payMoney) }} 元</span>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="银行联行号：" prop="bankNo" labelWidth="120px">
              <span>{{ (form.bankNo) }}</span>
            </el-form-item>
          </el-col>
        </el-row>
        <!--el-form-item label="成本费用" prop="payFee">
          <span>{{ (form.payFee) }} </span>
        </el-form-item>
              <el-form-item label="收款渠道:" prop="rcvChannel"  labelWidth="120px">
          <span>{{ (form.rcvChannel) }}</span>
        </el-form-item>
        <el-form-item-- label="商户费用" prop="merFee">
          <span>{{ (form.merFee) }} </span>
        </el-form-item-->
        <el-row>
          <el-col :span="10">
            <el-form-item label="上传日期:" prop="uploadDate" labelWidth="120px">
              <span>{{ parseTime(form.uploadDate) }} </span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="处理日期:" prop="transDate" labelWidth="120px">
           <span v-if="form.transDate == null">
            无
          </span>
              <span v-if="form.transDate != null">
             <span>{{ parseTime(form.transDate) }} </span>
          </span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="处理状态:" prop="transStatus" labelWidth="120px">
           <span v-if="form.transStatus == 0">
            <el-tag type="info" effect="dark" size="mini">未处理</el-tag>
          </span>
              <span v-if="form.transStatus == 1">
            <el-tag type="success" effect="dark" size="mini">成功</el-tag>
          </span>
              <span v-if="form.transStatus == 2">
            <el-tag type="danger" effect="dark" size="mini">失败</el-tag>
          </span>
              <span v-if="form.transStatus == 3">
           <el-tag type="warning" effect="dark" size="mini">处理中</el-tag>
          </span>
            </el-form-item>
          </el-col>

          <el-col :span="10">
            <el-form-item label="状态描述:" prop="transDesc" labelWidth="120px">
              <span >{{ (form.transDesc) }} </span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="开票状态:" prop="invoiceStatus" labelWidth="120px">
           <span v-if="form.invoiceStatus == 1">
          <el-tag type="info" effect="dark" size="mini">未开票</el-tag>
           </span>
              <span v-if="form.invoiceStatus == 2">
          <el-tag type="success" effect="dark" size="mini">已开票</el-tag>
        </span>
              <span v-if="form.invoiceStatus ==3">
          <el-tag type="waring" effect="dark" size="mini">开票中</el-tag>
        </span>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item label="税务申报状态:" prop="taxReqStatus" labelWidth="120px">
            <span v-if="form.taxReqStatus == 1">
          <el-tag type="success" effect="dark" size="mini">已申报</el-tag>
        </span>
              <span v-if="form.taxReqStatus ==2">
          <el-tag type="waring" effect="dark" size="mini">未申报</el-tag>
        </span>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="10">
            <el-form-item label="发票编号:" prop="invoiceId" labelWidth="120px">
              <span>{{ (form.invoiceId) }} </span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="税务申报日期:" prop="taxReqDate" labelWidth="120px">
          <span v-if="form.taxReqDate == null">
            无
          </span>
              <span v-if="form.taxReqDate != null">
            <span>{{ parseTime(form.taxReqDate) }}</span>
          </span>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>

    </el-dialog>

  </div>
</template>

<script>
import {
  listDetail,
  getDetail,
  delDetail,
  addDetail,
  updateDetail,
  exportDetail,
  checkDetail
} from "@/api/fund/detail";
import {getToken} from '@/utils/auth';
import ElInput from "../../../../node_modules/element-ui/packages/input/src/input.vue";

export default {
  components: {ElInput},
  data() {
    return {
      filePath: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      //付款渠道
      payChannelOptions: [],
      //付款类型 对公/对私
      payTypeFormatOptions: [],
      //处理状态
      bankStatyusOptions: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 日期范围
      dateRange: [],
      // 日期范围
      dateRange2: [],
      // 资金下发明细表格数据
      detailList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      excelUploadUrl: process.env.VUE_APP_BASE_API + '/fund/detail/upload',
      myHeaders: {Authorization: 'Bearer ' + getToken()},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        merId: undefined,
        payChannel: undefined,
        batchId: undefined,
        orderId: undefined,
        payName: undefined,
        payAccount: undefined,
        payBank: undefined,
        payType: undefined,
        payCardid: undefined,
        payMobile: undefined,
        payMoney: undefined,
        bankNo: undefined,
        rcvChannel: undefined,
        payFee: undefined,
        merFee: undefined,
        uploadDate: undefined,
        transDate: undefined,
        transStatus: undefined,
        invoiceId: undefined,
        invoiceStatus: undefined,
        taxReqStatus: undefined,
        taxReqDate: undefined,
        corpCode: undefined,
        corpName: undefined,
        reqIp: undefined,
        status: undefined,
        remarks: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        merId: [
          {required: true, message: "商户编号不能为空", trigger: "blur"}
        ], payChannel: [
          {required: true, message: "下发渠道不能为空", trigger: "blur"}
        ], batchId: [
          {required: true, message: "批次号不能为空", trigger: "blur"}
        ], orderId: [
          {required: true, message: "订单编号不能为空", trigger: "blur"}
        ], payName: [
          {required: true, message: "付款人不能为空", trigger: "blur"}
        ], payAccount: [
          {required: true, message: "付款账号不能为空", trigger: "blur"}
        ], payBank: [
          {required: true, message: "付款银行不能为空", trigger: "blur"}
        ], payType: [
          {required: true, message: "付款类型 1：公 2：私不能为空", trigger: "blur"}
        ], payCardid: [
          {required: true, message: "证件号码不能为空", trigger: "blur"}
        ], payMobile: [
          {required: true, message: "付款人手机号不能为空", trigger: "blur"}
        ], payMoney: [
          {required: true, message: "付款金额不能为空", trigger: "blur"}
        ], rcvChannel: [
          {required: true, message: "收款渠道 1：银行卡 2：支付宝 3：微信不能为空", trigger: "blur"}
        ], uploadDate: [
          {required: true, message: "上传日期不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("pay_Channel").then(response => {
      this.payChannelOptions = response.data;
    });
    this.getDicts("pay_Type").then(response => {
      this.payTypeFormatOptions = response.data;
    });
    this.getDicts("trans_status").then(response => {
      this.bankStatyusOptions = response.data;
    });
  },
  methods: {
    // 下方渠道字段
    payChannelFormat(row, column) {
      return this.selectDictLabel(this.payChannelOptions, row.payChannel);
    },
    //付款类型
    payTypeFormat(row, column) {
      return this.selectDictLabel(this.payTypeFormatOptions, row.payType);
    },
    /** 查询资金下发明细列表 */
    getList() {
      this.loading = true;
      listDetail(this.addDateCheckRange(this.queryParams, this.dateRange,this.dateRange2)).then(response => {
        this.detailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        merId: undefined,
        payChannel: undefined,
        batchId: undefined,
        orderId: undefined,
        payName: undefined,
        payAccount: undefined,
        payBank: undefined,
        payType: undefined,
        payCardid: undefined,
        payMobile: undefined,
        payMoney: undefined,
        bankNo: undefined,
        rcvChannel: undefined,
        payFee: undefined,
        merFee: undefined,
        uploadDate: undefined,
        transDate: undefined,
        transStatus: "0",
        invoiceId: undefined,
        invoiceStatus: "0",
        taxReqStatus: "0",
        taxReqDate: undefined,
        corpCode: undefined,
        corpName: undefined,
        createBy: undefined,
        createDate: undefined,
        reqIp: undefined,
        status: "0",
        updateBy: undefined,
        updateDate: undefined,
        remarks: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange=[],
        this.dateRange2=[],
        this.queryParams.transStatus=null,
        this.resetForm("queryForm");
        this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加资金下发明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDetail(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看详细";
      });
    },
    /*状态查询*/
    handleCheck(row) {
      this.reset();
      const id = row.id || this.ids
      return checkDetail(id).then(response => {
        if (response.code === 200) {
          this.msgSuccess("更新完成");
          this.open = false;
          this.getList();
        } else {
          this.msgError(response.msg);
        }
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateDetail(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addDetail(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除资金下发明细编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delDetail(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(function () {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出资金下发明细数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportDetail(queryParams);
      }).then(response => {
        this.download(response.msg);
      }).catch(function () {
      });
    },
    beforeAvatarUpload(file) {
      var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
      const extension = testmsg === 'xls'
      const extension2 = testmsg === 'xlsx'
      const isLt2M = file.size / 1024 / 1024 < 5
      if (!extension && !extension2) {
        this.$message({
          message: '上传文件只能是 xls、xlsx格式!',
          type: 'warning'
        });
      }
      if (!isLt2M) {
        this.$message({
          message: '上传文件大小不能超过 5M!',
          type: 'warning'
        });
      }
      return extension || extension2 && isLt2M
    },
    /** 处理图片批量上传*/
    handleImageBatchUpload(res) {
      if (res.code === 200) {
        this.msgSuccess("上传成功!");
      } else {
        this.msgError(res.msg);
      }
    },


  }
};
</script>
